CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
CMAKE_POLICY(VERSION 2.6)


IF(NOT LIBSHM_INSTALL_LIB_SUBDIR)
  SET(LIBSHM_INSTALL_BIN_SUBDIR "bin" CACHE PATH "libshm install binary directory")
  SET(LIBSHM_INSTALL_LIB_SUBDIR "lib" CACHE PATH "libshm install library directory")
ENDIF()

ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE=1)
ADD_DEFINITIONS(-DSHM_EXPORTS)

IF (CMAKE_VERSION VERSION_LESS "3.1")
  SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
ELSE ()
  SET(CMAKE_CXX_STANDARD 11)
ENDIF ()

ADD_LIBRARY(shm SHARED core.cpp)

target_include_directories(shm PRIVATE
  ${CMAKE_SOURCE_DIR}/aten/src/TH # provides "THAllocator.h" to THCGeneral.h
  ${CMAKE_BINARY_DIR}/aten/src # provides "ATen/TypeExtendedInterface.h" to ATen.h
  ${CMAKE_BINARY_DIR}/caffe2/aten/src # provides <TH/THGeneral.h> to THC.h
  ${CMAKE_BINARY_DIR}/caffe2/aten/src/THC # provides "THCGeneral.h" to THC.h
  )

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
TARGET_LINK_LIBRARIES(shm caffe2 c10)


INSTALL(TARGETS shm
          RUNTIME DESTINATION "${LIBSHM_INSTALL_BIN_SUBDIR}"
          LIBRARY DESTINATION "${LIBSHM_INSTALL_LIB_SUBDIR}"
          ARCHIVE DESTINATION "${LIBSHM_INSTALL_LIB_SUBDIR}")
INSTALL(FILES libshm.h DESTINATION "include")
